@bg-base: #fff;
@bg-secondary: #f4f4f4;
@bg-dark: #eee;
@bg-black: #393f52;
@bg-controller-active: #fafafa;
@bg-controller-disabled: #b2b2b2;

@mask-base: rgba(0, 0, 0, 0.45);

@shadow-base: rgba(35, 35, 35, 0.08);
@shadow-secondary: rgba(153, 153, 153, 0.08);

@color-base: #232323;
@color-inverse: #fff;
@color-caption: #777777;
@color-tip: #b2b2b2;
@color-icon: #9a9cab;

@line-base: #bdbae3;
@line-lighter: #eaeaea;

@brand-primary: #1fadb6;
@brand-primary-tap: #23969d;
@brand-warning: #ff5126;
@brand-warning-tap: #e63c12;

@radius-tiny: 4px;
@radius-controller: 6px;
@radius-block: 8px;
@radius-article: 12px;

@keyframes off_page_show {
  0% {
    opacity: 0;
    transform: translateY(-30%);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popover_show {
  0% {
    opacity: 0;
    transform: scale(0.6);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.border1px (@top, @right, @bottom, @left, @radius: 0) {
  position: relative;
  border-width: 0;

  &::before {
    box-sizing: border-box;
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    width: 100%;
    height: 100%;
    border-style: inherit;
    border-color: inherit;
    border-radius: @radius;
    border-width: @top @right @bottom @left;
    pointer-events: none;
    content: "";
  }

  @media screen and (-webkit-min-device-pixel-ratio: 2) {
    &::before {
      width: 200%;
      height: 200%;
      transform-origin: 0 0;
      transform: scale(0.5) translateZ(0);
      border-radius: @radius*2;
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 3) {
    &::before {
      width: 300%;
      height: 300%;
      transform-origin: 0 0;
      transform: scale(1/3) translateZ(0);
      border-radius: @radius*3;
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 4) {
    &::before {
      width: 400%;
      height: 400%;
      transform-origin: 0 0;
      transform: scale(1/4) translateZ(0);
      border-radius: @radius*4;
    }
  }
}

.popover() {
  border: solid @line-base;
  .border1px(1px, 1px, 1px, 1px,@radius-controller);
  border-radius: @radius-controller;
  position: absolute;
  z-index: 1001;
  background: @bg-base;
  box-shadow: 0 0 30px @shadow-base;
  transform-origin: 50% 50%;
  animation: popover_show 0.2s ease-out 0s both;
}

//左下弹出 position = 1, 右下弹出 position = 2;
.popover(@position)when(@position>0) {
  .popover();

  &:after {
    box-sizing: border-box;
    position: absolute;
    left: 30px;
    top: 1px;
    display: block;
    width: 8px;
    height: 8px;
    z-index: 1;
    background: @bg-base;
    border: solid @line-base;
    border-width: 1px 0 0 1px;
    transform-origin: 50% 50%;
    transform: rotate(45deg);
    margin: -4px 0 0 -4px;
    content: "";
  }

  @media screen and (-webkit-min-device-pixel-ratio: 2) {
    &::after {
      width: 16px;
      height: 16px;
      margin: -8px 0 0 -8px;
      transform: rotate(45deg) scale(1/2) translateZ(0);
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 3) {
    &::after {
      width: 24px;
      height: 24px;
      margin: -12px 0 0 -12px;
      transform: rotate(45deg) scale(1/3) translateZ(0);
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 3) {
    &::after {
      width: 32px;
      height: 32px;
      margin: -16px 0 0 -16px;
      transform: rotate(45deg) scale(1/4) translateZ(0);
    }
  }

  transform-origin: 36px -6px;
}

.popover(@position)when(@position=2) {
  &:after {
    left: calc(100% - 30px);
  }

  transform-origin: calc(100% - 36px) -6px;
}

.popover(@position)when(@position>2) {
  &:after {
    top: auto;
    bottom: 1px;
    transform: rotate(-135deg);
    margin: 0 0 -4px -4px;
  }

  @media screen and (-webkit-min-device-pixel-ratio: 2) {
    &::after {
      margin: 0 0 -8px -8px;
      transform: rotate(-135deg) scale(1/2) translateZ(0);
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 3) {
    &::after {
      margin: 0 0 -12px -12px;
      transform: rotate(-135deg) scale(1/3) translateZ(0);
    }
  }

  @media screen and (-webkit-min-device-pixel-ratio: 3) {
    &::after {
      margin: 0 0 -16px -16px;
      transform: rotate(-135deg) scale(1/4) translateZ(0);
    }
  }

  transform-origin: 36px calc(100% + 6px);
}

.popover(@position)when(@position=4) {
  &:after {
    left: calc(100% - 30px);
  }
  transform-origin: calc(100% - 36px) calc(100% + 6px);
}
